package com.example.cheng.controller;

import com.example.cheng.pojo.User;
import io.swagger.annotations.*;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "测试1")
@RequestMapping("/hello")
public class HelloController {

    @ApiOperation(value = "你好")
    @GetMapping("/hello")
//    @ApiImplicitParams({
//            @ApiImplicitParam(paramType = "query", name = "id", value = "账号", required = true, dataType = "String"),
//            @ApiImplicitParam(paramType = "query", name = "name", value = "姓名", required = true, dataType = "String"),
//            @ApiImplicitParam(paramType = "query", name = "age", value = "年龄", required = false, dataType = "Integer"),
//    })
    public List<User> hello() {
        User user1 = new User("12346", "cheng", "123456", 18, "男");
        User user2 = new User("123456", "meng", "123456", 18, "女");
        ArrayList<User> userList = new ArrayList<>();
        userList.add(user1);
        userList.add(user2);
        return userList;
    }

    @ApiOperation(value = "不好")
    @PostMapping("/nohello")
    @ApiImplicitParam(paramType = "body", name = "user", value = "用户", required = true, dataType = "User")
    public ResponseEntity<String> nohello(User user){
        if (user.getId() == null){
            return new ResponseEntity<>("id不可为空", HttpStatus.BAD_REQUEST);
        }
        return new ResponseEntity<>("用户验证成功", HttpStatus.OK);
    }
}